home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / oji / nsIThreadManager.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  5KB  |  152 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. #ifndef nsIThreadManager_h___
  39. #define nsIThreadManager_h___
  40.  
  41. #include "nsISupports.h"
  42. #include "nspr.h"
  43.  
  44. ////////////////////////////////////////////////////////////////////////////////
  45.  
  46. ////////////////////////////////////////////////////////////////////////////////
  47. // Thread Manager
  48. // This interface provides thread primitives.
  49.  
  50. #define NS_ITHREADMANAGER_IID                           \
  51. { /* 97bb54c0-6846-11d2-801f-00805f71101c */            \
  52.     0x97bb54c0,                                            \
  53.     0x6846,                                                \
  54.     0x11d2,                                                \
  55.     {0x80, 0x1f, 0x00, 0x80, 0x5f, 0x71, 0x10, 0x1c}    \
  56. }
  57.  
  58. class nsIRunnable;
  59.  
  60. class nsIThreadManager : public nsISupports {
  61. public:
  62.     NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITHREADMANAGER_IID)
  63.     
  64.     /**
  65.      * Returns a unique identifier for the "current" system thread.
  66.      */
  67.     NS_IMETHOD
  68.     GetCurrentThread(PRThread* *threadID) = 0;
  69.  
  70.     /**
  71.      * Pauses the current thread for the specified number of milliseconds.
  72.      * If milli is zero, then merely yields the CPU if another thread of
  73.      * greater or equal priority.
  74.      */
  75.     NS_IMETHOD
  76.     Sleep(PRUint32 milli = 0) = 0;
  77.     
  78.     /**
  79.      * Creates a unique monitor for the specified address, and makes the
  80.      * current system thread the owner of the monitor.
  81.      */
  82.     NS_IMETHOD
  83.     EnterMonitor(void* address) = 0;
  84.     
  85.     /**
  86.      * Exits the monitor associated with the address.
  87.      */
  88.     NS_IMETHOD
  89.     ExitMonitor(void* address) = 0;
  90.     
  91.     /**
  92.      * Waits on the monitor associated with the address (must be entered already).
  93.      * If milli is 0, wait indefinitely.
  94.      */
  95.     NS_IMETHOD
  96.     Wait(void* address, PRUint32 milli = 0) = 0;
  97.  
  98.     /**
  99.      * Notifies a single thread waiting on the monitor associated with the address (must be entered already).
  100.      */
  101.     NS_IMETHOD
  102.     Notify(void* address) = 0;
  103.  
  104.     /**
  105.      * Notifies all threads waiting on the monitor associated with the address (must be entered already).
  106.      */
  107.     NS_IMETHOD
  108.     NotifyAll(void* address) = 0;
  109.  
  110.     /**
  111.      * Creates a new thread, calling the specified runnable's Run method (a la Java).
  112.      */
  113.     NS_IMETHOD
  114.     CreateThread(PRThread **thread, nsIRunnable* runnable) = 0;
  115.     
  116.     /**
  117.      * Posts an event to specified thread, calling the runnable from that thread.
  118.      * @param threadID thread to call runnable from
  119.      * @param runnable object to invoke from thread
  120.      * @param async if true, won't block current thread waiting for result
  121.      */
  122.     NS_IMETHOD
  123.     PostEvent(PRThread* thread, nsIRunnable* runnable, PRBool async) = 0;
  124. };
  125.  
  126. ////////////////////////////////////////////////////////////////////////////////
  127.  
  128. ////////////////////////////////////////////////////////////////////////////////
  129. // Runnable
  130. // This interface represents the invocation of a new thread.
  131.  
  132. #define NS_IRUNNABLE_IID                                \
  133. { /* 930f3d70-6849-11d2-801f-00805f71101c */            \
  134.     0x930f3d70,                                            \
  135.     0x6849,                                                \
  136.     0x11d2,                                                \
  137.     {0x80, 0x1f, 0x00, 0x80, 0x5f, 0x71, 0x10, 0x1c}    \
  138. }
  139.  
  140. class nsIRunnable : public nsISupports {
  141. public:
  142.     NS_DEFINE_STATIC_IID_ACCESSOR(NS_IRUNNABLE_IID)
  143.  
  144.     /**
  145.      * Defines an entry point for a newly created thread.
  146.      */
  147.     NS_IMETHOD
  148.     Run() = 0;
  149. };
  150.  
  151. #endif /* nsIThreadManager_h___ */
  152.